package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.AccountInfoBean;
import com.koron.css2.clientCenter.bean.CtmInfoBean;
import com.koron.css2.clientCenter.bean.UserBean;
import com.koron.css2.clientCenter.bean.UserTransferInfoBean;
import com.koron.css2.clientCenter.mapper.AccountInfoMapper;
import com.koron.css2.clientCenter.mapper.CtmInfoMapper;
import com.koron.css2.clientCenter.mapper.TransferUserMapper;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 过户删除
 * @author 甄玉晴
 *
 */
public class TransferUserDelete implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			TransferUserMapper mapper = factory.getMapper(TransferUserMapper.class);
			UserInfoMapper userMapper = factory.getMapper(UserInfoMapper.class);
			AccountInfoMapper accountMapper = factory.getMapper(AccountInfoMapper.class);
			CtmInfoMapper ctmMapper = factory.getMapper(CtmInfoMapper.class);
			UserTransferInfoBean bean = JsonUtils.objectToPojo(req.getData(), UserTransferInfoBean.class);
			bean = mapper.getUserTransferInfoById(bean.getId());//获取过户记录信息
			if(bean==null) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "该过户信息不存在", void.class);
			}
			if(bean.getProcessState()!=null&&!bean.getProcessState().equals("")) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "状态为草稿，该过户信息不能删除", void.class);
			}
			accountMapper.accountInfoDelete(bean.getUserAccountTempId(),AccountInfoBean.ACCOUNTTEMP);// 删除临时账户信息
			ctmMapper.ctmInfoDelete(bean.getUserCtmTempId(),CtmInfoBean.CTMTEMP);// 删除临时客户信息
			userMapper.userInfoDelete(bean.getAfterUserInfoTempId(),UserBean.USERTEMP);//删除过户后临时用户信息
			userMapper.userInfoDelete(bean.getBeforeUserInfoTempId(),UserBean.USERTEMP);//删除过后前临时用户信息
			mapper.userTransferDelete(bean.getId());//删除过户记录信息
		
			return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
		} catch (Exception e) {
			logger.error("过户信息删除失败", e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "过户信息删除失败", void.class);
		}
	}

}
